import { h, Component } from 'preact';
import classNames from 'classnames';
import s from './InvitedRecord.scss';
import defaultImg from '../../assets/defaultImg.png';
import { getRecommendInfoListAction } from '~/actions/user';
import { datePattern } from '~/utils/common/common';
import MessageBox from '~/components/Message';
import { connect } from 'preact-redux';
class InvitedRecord extends Component {
	constructor() {
		super();
	}
	componentWillMount(){
		const { dispatch } = this.props;
		dispatch(getRecommendInfoListAction()).catch(err => {
			MessageBox.show({title: err.errorMsg || '系统错误'});
		});
	}
	render() {
		const { recommendInfo } = this.props;
		return (
			<div className={s.table}>
				<div className={s.header}>
					<span>
						微信好友
					</span>
					<span>
						邀请时间
					</span>
					<span>
						获得积分
					</span>
				</div>
				<div className={s.body}>
					<ul>
						{recommendInfo.map(item => (<li>
							<span className={s.name}>
								<img src={item.userImg || defaultImg} className={s.headImg}/>
								{item.userNickname || '-'}
							</span>
							<span className={s.date}>
								{item.businessTime.toString().replace(datePattern,'$2/$3 $4:$5')}
							</span>
							<span className={s.score}>
								+	{item.addScore || '0'}
							</span>
						</li>))}
					</ul>
				</div>

				<div className={s.footer}></div>
			</div>
		);
	}
}

export default connect(state => (state))(InvitedRecord);
